<?php $form=$this->beginWidget('booster.widgets.TbActiveForm',array(
	'id'=>'noticias-form',
	'enableAjaxValidation'=>false,
	 'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>

<link rel="stylesheet" href="<?php echo Yii::app()->homeUrl;?>css/fm.selectator.jquery.css"/>

<script src="<?php echo Yii::app()->homeUrl;?>js/fm.selectator.jquery.js"></script>

<p class="help-block">Fields with <span class="required">*</span> are required.</p>

<?php //echo $form->errorSummary($model); ?>

 <?php 
        foreach(Yii::app()->user->getFlashes() as $key => $message) {
            echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
        }
    ?>

	<?php echo $form->textFieldGroup($model,'titulo',array('widgetOptions'=>array('htmlOptions'=>array('class'=>'span5','maxlength'=>100)))); ?>

	<?php echo $form->textFieldGroup($model,'ante_titulo',array('widgetOptions'=>array('htmlOptions'=>array('class'=>'span5','maxlength'=>150)))); ?>

	<?php echo $form->textFieldGroup($model,'sumario',array('widgetOptions'=>array('htmlOptions'=>array('class'=>'span5','maxlength'=>255)))); ?>

	<?php //echo $form->textAreaGroup($model,'cuerpo_noticia', array('widgetOptions'=>array('htmlOptions'=>array('rows'=>6, 'cols'=>50, 'class'=>'span8')))); ?>

	<?php //echo $form->textFieldGroup($model,'prioridad_noticia',array('widgetOptions'=>array('htmlOptions'=>array('class'=>'span5')))); ?>

	<?php $this->widget('application.extensions.eckeditor.ECKEditor', array(
                'model'=>$model,
                'attribute'=>'cuerpo_noticia',
               //'label' => 'Cuerpo de la noticia',
                'config' => array(
                    'toolbar'=>array(
                        array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Format', 'Font', 'FontSize', 'NumberedList', 'BulletedList',  'Strike', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'),
                        //array( 'Image', 'Link', 'Unlink', 'Anchor' ) ,
                    ),
                  ),
                )); ?>
	
	<?php echo $form->checkBoxGroup($model,'prioridad_fija'); ?>

    <?php

		echo $form->dropDownListGroup($model,'prioridad_noticia',
										array(
											'wrapperHtmlOptions' => array(
												'class' => 'col-sm-5',
											),
											'label'=>Yii::t('msg','Prioridad noticia'),
											'widgetOptions' => array(
												//'id'=>'partida',
												//'name'=>'partida',
												'data' =>array(1 => "1 -- Mas alta", 2 => "2", 3 => "3", 4 => "4", 5 => "5", 6 => "6", 7 => "7", 8 => "8", 9 => "9", 10 => "10 -- Mas baja"),
												//'options'=>array($model->proyecto_id => array('selected'=>true)),
												'htmlOptions' => array('id'=>'prioridad_noticia', 'prompt' => 'Seleccionar prioridad', //'onChange'=>'submit','submit' => array('/planificacion/importado','#'=>'partida') 
																		),
											),
											//'hint' => 'Tipo de archivo a cargar.'
										));

	?>

	<?php if(Yii::app()->user->checkAccess('coordinador'))
				echo $form->datePickerGroup($model,'fecha_publicacion',array('widgetOptions'=>array('options'=>array('format' => 'yyyy-mm-dd','startDate'=>date('Y-m-d'),'language'=>Yii::app()->language),  'htmlOptions'=>array('class'=>'span5')), 'hint'=>'Fecha de publicaci&oacute;n de la noticia','prepend'=>'<i class="glyphicon glyphicon-calendar"></i>', /*'append'=>'Click on Month/Year to select a different Month/Year.'*/)); ?>

	<?php //echo $form->textFieldGroup($model,'hora_publicacion',array('widgetOptions'=>array('htmlOptions'=>array('class'=>'span5')))); ?>

	<?php
	
			if(Yii::app()->user->checkAccess('coordinador'))
			{
				echo CHtml::label(CHtml::encode('Hora de publicación: '),'hora_publicacion');
					$this->widget(
						    'booster.widgets.TbTimePicker',
		
						    array(
						    	'model'=>$model,
						        'attribute'=>'hora_publicacion',
						        'name' => 'hora_publicacion',
						        //'label' => 'Hora de publicación',
						        'noAppend' => true,
						        'options'=>array('showMeridian'=>false),
						    	'wrapperHtmlOptions' => array('class' => 'span5')));
			}
	?>

	<?php //echo $form->textFieldGroup($model,'creado_por',array('widgetOptions'=>array('htmlOptions'=>array('class'=>'span5')))); ?>

	<?php //echo $form->textFieldGroup($model,'autorizado_por',array('widgetOptions'=>array('htmlOptions'=>array('class'=>'span5')))); ?>

	<?php //echo $form->datePickerGroup($model,'fecha_creacion',array('widgetOptions'=>array('options'=>array(),'htmlOptions'=>array('class'=>'span5')), 'prepend'=>'<i class="glyphicon glyphicon-calendar"></i>', /*'append'=>'Click on Month/Year to select a different Month/Year.'*/)); ?>

	<?php if(Yii::app()->user->checkAccess('coordinador'))
			echo $form->checkBoxGroup($model,'publicado',array('label'=>'Publicar')); 
			?>

	
<!--      <select id="myDropdown">
        <option value="0" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png"
            data-description="Description with Facebook">Facebook</option>
        <option value="1" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png"
            data-description="Description with Twitter">Twitter</option>
        <option value="2" selected="selected" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/linkedin-icon-32.png"
            data-description="Description with LinkedIn">LinkedIn</option>
        <option value="3" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/foursquare-icon-32.png"
            data-description="Description with Foursquare">Foursquare</option>
    </select> -->



	<?php 
			//echo $form->textFieldGroup($model,'portada',array('widgetOptions'=>array('htmlOptions'=>array('class'=>'span5'))));
		
			$imagenes = TiposArchivos::model()->findByAttributes(array('ext'=>'png'))->archivos;

			$list = CHtml::listData($imagenes, 'id', 'titulo');
 			//print_r($list);
			$options = array();
			foreach ($imagenes as $key => $value) {
				$options[$value->id] = array('data-subtitle'=>$value->ante_titulo, 'data-left'=>CHtml::image(Yii::app()->homeUrl.$value->ruta));
			}
			$htmlOptions =  array(/*'empty'=>'Seleccionar portada',*/ 'options'=>$options );//array('empty' => 'Select...');

			echo CHtml::label(CHtml::encode('Seleccionar Portada: '),'portada');

			echo '<select id="portada" class="form-control" name="Noticias[portada]" placeholder="Portada">'
			.CHtml::listOptions($model->portada, $list, $htmlOptions).'</select>';


		    	
	/*		echo $form->dropDownListGroup($model, 'portada',
													array(
														'wrapperHtmlOptions' => array(
															'class' => 'col-sm-5',
														),
														'label'=>Yii::t('msg','Imágen Portada'),
														'widgetOptions' => array(
															//'id'=>'partida',
															//'name'=>'partida',
															'data' => $list,
															//'options'=>array($model->proyecto_id => array('selected'=>true)),
															'htmlOptions' => array('id'=>'prioridad_noticia', 'prompt' => 'Seleccionar Imágen Portada', //'onChange'=>'submit','submit' => array('/planificacion/importado','#'=>'partida') 
																					),
														),
														//'hint' => 'Tipo de archivo a cargar.'
													));*/
	 ?>



	<?php 
		echo CHtml::label(CHtml::encode('Seleccionar imagenes(maximo '.Yii::app()->params['limite_imagenes'].'): '),'imagenes_id');
		$list = CHtml::listData(TiposArchivos::model()->findByAttributes(array('ext'=>'png'))->archivos, 'id', 'titulo');
			
		echo '<br>';
			/*$htmlOptions =  array('empty'=>'Seleccionar Imagenes', 'options'=>$options );//array('empty' => 'Select...');
			echo '<select id="portada" class="form-control" name="Noticias[portada]" placeholder="Portada" multiple="multiple">'
			.CHtml::listOptions($model->portada, $list, $htmlOptions).'</select>';*/

			$imagenes = NoticiasFotos::model()->findAllByAttributes(array('noticia_id'=>$model->id));
			$imgsSel = array();
			foreach ($imagenes as $key => $value) {
				$imgsSel[$value->archivo->id] = array('selected'=>true);
			}
/*			$this->widget(
			    'booster.widgets.TbSelect2',
			    array(
			    	'model'=>$model,
			    	'attribute'=>'imagenes_id',
			        //'name' => 'imagenes_id',
			        //'asDropDownList'=>true,			        
			        'data' => $list, //array('RU' => 'Russian Federation', 'CA' => 'Canada', 'US' => 'United States of America', 'GB' => 'Great Britain'),
			        'htmlOptions' => array(
			            'multiple' => 'multiple',
			            'options' =>  // selected options by default
								        $imgsSel
								        
			        ),
			    )
			);*/

			echo '<br> <br>';
			$options = array();
			foreach (TiposArchivos::model()->findByAttributes(array('ext'=>'png'))->archivos as $key => $value) {
				$options[$value->id] = array( 'data-left'=>CHtml::image(Yii::app()->homeUrl.$value->ruta),);
			}

			$htmlOptions = array( 'options'=>$options );//array('empty' => 'Select...');
			echo '<select multiple="multiple" id="imagenes" class="form-control" name="Noticias[imagenes_id][]" placeholder="Imagenes">'
			.CHtml::listOptions($model->imagenes_id, $list, $htmlOptions).'</select>';

	?>

	<script language="javascript">
			$(document).ready(function(e) {
				try {
					$('select#portada').selectator({
					    prefix: 'selectator_',             // CSS class prefix
					    height: 'auto',                    // auto or element
					    useDimmer: false,                  // dims the screen when option list is visible
					    useSearch: true,                   // if false, the search boxes are removed and 
					                                       //   `showAllOptionsOnFocus` is forced to true
					    keepOpen: false,                   // if true, then the dropdown will not close when 
					                                       //   selecting options, but stay open until losing focus
					    showAllOptionsOnFocus: false,      // shows all options if input box is empty
					    selectFirstOptionOnSearch: true,   // selects the topmost option on every search
					    searchCallback: function(value){}, // Callback function when enter is pressed and 
					                                       //   no option is active in multi select box
					    labels: {
					        search: 'Buscar...'            // Placeholder text in search box in single select box
					    }
					});
					$('select#imagenes').selectator({
					    prefix: 'selectator_',             // CSS class prefix
					    height: 'auto',                    // auto or element
					    useDimmer: false,                  // dims the screen when option list is visible
					    useSearch: true,                   // if false, the search boxes are removed and 
					                                       //   `showAllOptionsOnFocus` is forced to true
					    keepOpen: true,                   // if true, then the dropdown will not close when 
					                                       //   selecting options, but stay open until losing focus
					    showAllOptionsOnFocus: true,      // shows all options if input box is empty
					    selectFirstOptionOnSearch: false,   // selects the topmost option on every search
					    searchCallback: function(value){}, // Callback function when enter is pressed and 
					                                       //   no option is active in multi select box
					    labels: {
					        search: 'Buscar...'            // Placeholder text in search box in single select box
					    }
					});
				} catch(e) {
					alert(e.message);
				}
			});
	</script> 



<!-- 
<input id="imagenes_id" type="hidden" name='Noticias[imagenes_id[]]' value="" />
<script type="text/javascript">
/*			$('select#imagenes').ddslick({
			    onSelected: function(data){
			        //callback function: do something with selectedData;
 			        //var $_POST["Noticias"]["portada"] = selectedData;
					//document.write($_POST["Noticias"]["portada"])\

					$('#portada_id').val(data.selectedData.value);
					//$('#portada_id').submit();
			    }   
			});*/
    	</script>
 -->
<div class="form-actions">
	<?php $this->widget('booster.widgets.TbButton', array(
			'buttonType'=>'submit',
			'context'=>'primary',
			'label'=>$model->isNewRecord ? Yii::t('msg','Crear') : Yii::t('msg','Guardar'),
		)); ?>
</div>

<?php $this->endWidget(); ?>






    	  